package 越短越合法

func beautifulBouquet(flowers []int, cnt int) int {
	diff := map[int]int{}
	left := 0
	result := 0
	for right, n := range flowers {
		diff[n]++
		for diff[n] > cnt && left <= right {
			diff[flowers[left]]--
			left++
		}
		result += right - left + 1
	}
	return result % 1_000_000_007
}
